$(function(){

    new Swiper('#index_banner .swiper-container', {
        autoplay: {
          delay: 2000
        },
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
    })
    if($('#colorful_swiper').length>0) {
        new Swiper('#colorful_swiper .swiper-container', {

            autoplay: true,
            navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev',
            },
        })
    }

    var galleryTop = new Swiper('.gallery-top', {
        width: 250,
        // loop: true,
        // slidesPerView: 2,
        breakpoints: {
            0: {
                height: 72,
            },
            1000: {
                height: 120,
            },
        },
        direction: "vertical",
        spaceBetween: 10,
        virtualTranslate: true,
        allowTouchMove: false,
    });

    new Swiper('.gallery-thumbs', {
        slidesPerView: 1,
        watchSlidesVisibility: true,
        watchSlidesProgress: true,
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
        spaceBetween: 2,
        thumbs: {
            swiper: galleryTop,
        },
    });


    var goodsTop = new Swiper('.goods-top', {
        height: 120,
        slidesPerView: 3.1,
        spaceBetween: 0,
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
    });

    new Swiper('.goods-thumbs', {
        slidesPerView: 1,
        watchSlidesVisibility: true,
        watchSlidesProgress: true,
        thumbs: {
            swiper: goodsTop,
        },
    });

})



/*表单提交 start*/
function message(){
    var addr = $('#addr').val();
    if (addr == "") {
        my_alert('请输入所在地区');
        return false;
    }

    var product = $('#product').val();
    if (product == "") {
        my_alert('请选择产品类型');
        return false;
    }

    var username = $('#username').val();
    if (username == "") {
        my_alert('请输入联系人');
        return false;
    }

    var telephone = $('#telephone').val();
    if (telephone == "") {
        my_alert('请输入手机号');
        return false;
    }else {
        var myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
        if (!myreg.test(telephone)) {
            my_alert('手机格式不正确');
            return false;
        }
    }

    $.post("/index/index/message",{
        addr: addr,
        product: product,
        telephone:telephone,
        username:username,
    },function(res){
        my_alert(res.msg);
    })
    return false;
}
/*表单提交 end*/


/*自定义 my_alert() start*/
function my_alert(msg){
    var timestamp=new Date().getTime();
    var alert_id = 'alert'+timestamp;
    $('body').after("<div class='my_alert' id='" + alert_id + "'>"+ msg +"</div>");
    setTimeout(function(){
        $('#'+alert_id).remove();
    },3000)
}
/*自定义 my_alert() end*/




$(function(){
    // nav收缩展开
    $('.navMenu li a').on('click',function(){
        var parent = $(this).parent().parent();//获取当前页签的父级的父级
        var labeul =$(this).parent("li").find(">ul")

        if ($(this).parent().hasClass('open') == false) {
            //展开未展开
            parent.find('ul').slideUp(300);
            parent.find("li").removeClass("open");
            // $('.navMenu li ').removeClass("active");
            parent.find('li a').removeClass("active").find(".arrow").removeClass("open")
            $(this).parent("li").addClass("open").find(labeul).slideDown(300);

            $(this).addClass("active").find(".arrow").addClass("open")
        }else{
            $(this).parent("li").removeClass("open").find(labeul).slideUp(300);

            if($(this).parent().find("ul").length>0){
                $(this).removeClass("active").find(".arrow").removeClass("open")
            }else{
                $(this).addClass("active")
            }
        }

    });
    var protocol = window.location.protocol;
    var host = location.host;
    if (!/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
        //$('.navMenu li.active a').trigger('click');
    }

    $(".mobile-inner-header-icon").click(function(){
        $(this).toggleClass("mobile-inner-header-icon-click mobile-inner-header-icon-out");
        $(".mobile-inner-nav").slideToggle(250);
    });
    $(".mobile-inner-nav a").each(function( index ) {
        $( this ).css({'animation-delay': (index/10)+'s'});
    });

    $(".header ul li").hover(
        function() {
            $(".header ul .sub").show();
            $(".bg").show();

        },
        function() {
            $(".header ul .sub").hide();
            $(".bg").hide();
        }
    );

});